package com.gong.yuanma.lock;

/**
 * @author GongChang
 * @version 1.0
 * @date 2021/7/22 0022 21:37
 */

public class DeadLock {

    static volatile Integer a = 0;

    public static void main(String[] args) {
        Object o = new Object();
        new Thread(()->{
            while (true){
                synchronized (a){
                    try {
                        while (a > 0){
                            a.wait();
                        }
                        System.out.println("生产:"+(++a));
                        a.notifyAll();
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }
        }).start();

        new Thread(()->{
            while (true){
                synchronized (a){
                    try {
                        while (a <= 0){
                            a.wait();
                        }
                        System.out.println("消费:"+(--a));
                        a.notifyAll();
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }
        }).start();

    }

}
